package Javaa.Base;
// create an example of using Seralize class
import java.io.*;
public class SeralizeExample {
    public static void main(String[] args) {
        // Define the Person class and make it serializable
        class Person implements Serializable {
            private String name;
            private int age;
        
            public Person(String name, int age) {
                this.name = name;
                this.age = age;
            }
            @Override
            public String toString() {
                return "Person{name='" + name + "', age=" + age + "}";
            }
        }
        
        // Create an object to serialize
        Person person = new Person("John", 30);

        // Serialize the object
        try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("person.ser"))) {
            oos.writeObject(person);
            System.out.println("Object serialized: " + person);
        } catch (IOException e) {
            e.printStackTrace();
        }
        
        
        

        // Deserialize the object
        try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream("person.ser"))) {
            Person deserializedPerson = (Person) ois.readObject();
            System.out.println("Object deserialized: " + deserializedPerson);
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}